from Dataset.Dataset import Dataset
title = "Semeion"
file_name = r"""..\Datasets\SemeionData.txt"""

a = Dataset(title, file_name)

d1 = a.data

#import os

#import DataSetFileParsing
#import AttributeSelectors
#from DecisionTree import *

## Sample calls:
##results = DecisionTreeTestHarness.run_decision_tree_test(
##	"./SampleDataSets/Poker/Poker-TrainingDataSet.txt",
##	"./SampleDataSets/Poker/Poker-TestingDataSet.txt"
##)

##results = DecisionTreeTestHarness.run_decision_tree_test(
##	"./SampleDataSets/Contraceptives/Contraceptives-DataSet.txt",
##	None)

#def run_decision_tree_test(training_file, testing_file):
#	
#	print("Loading Training Dataset...")
#	(attributeNames, dataset) = DataSetFileParsing.load_data_set(training_file)

#	print("Constructing Decision Tree...")
#	decision_tree = DecisionTree(attributeNames, dataset)

#	results = {}
#	results["DecisionTree"] = decision_tree

#	print("Testing Decision Tree against training data...")
#	results["TrainingFile"] = training_file
#	results["TrainingDataResults"] = test_decision_tree(training_file, decision_tree)
#	
#	if testing_file == None:
#		return results

#	print("Testing Decision Tree against testing data...")
#	results["TestingFile"] = testing_file
#	results["TestingDataResults"] = test_decision_tree(testing_file, decision_tree)

#	print("Writing report files...")
#	file = open(training_file.replace(os.path.basename(training_file), "DecisionTreeReports/" + os.path.basename(training_file)[:-4]) + "-DecisionTree.txt",  "w")
#	file.write("Generated Decision Tree Report:\n\n")
#	file.write("Training File: {0}\n".format(training_file))
#	file.write("Performance Against Training Set:\n")
#	file.write("Percent Correct: {0}\n".format(results["TrainingDataResults"]["Correct"]/results["TrainingDataResults"]["Total"]))
#	file.write("Percent Incorrect: {0}\n".format(results["TrainingDataResults"]["Incorrect"]/results["TrainingDataResults"]["Total"]))
#	file.write("Accuracy with respect to label:\n")
#	keys = results["TrainingDataResults"]["Distribution"].keys()
#	keys.sort()
#	for key in keys:
#		file.write("{0}: {1}\n".format(key, results["TrainingDataResults"]["Distribution"][key]))
#	file.write("\n")
#	file.write("Testing File: {0}\n".format(testing_file))
#	file.write("Performance Against Testing Set:\n")
#	file.write("Percent Correct: {0}\n".format(results["TestingDataResults"]["Correct"]/results["TestingDataResults"]["Total"]))
#	file.write("Percent Incorrect: {0}\n".format(results["TestingDataResults"]["Incorrect"]/results["TestingDataResults"]["Total"]))
#	file.write("Accuracy with respect to label:\n")
#	keys = results["TestingDataResults"]["Distribution"].keys()
#	keys.sort()
#	for key in keys:
#		file.write("{0}: {1}\n".format(key, results["TestingDataResults"]["Distribution"][key]))
#	file.write("\n")
#	file.write("\n")
#	file.write("DecisionTree:\n")
#	file.write("Size: {0}\n".format(results["DecisionTree"].Size()))
#	file.write("Leaves: {0}\n".format(results["DecisionTree"].Leaves()))
#	file.write(results["DecisionTree"].to_string())
#	file.close()

#	return results

#def test_decision_tree(testing_file, decision_tree):
#	results = {}
#	results["File"] = testing_file
#	results["Total"] = 0.0
#	results["Correct"] = 0.0
#	results["Incorrect"] = 0.0
#	results["Distribution"] = {}
#	for record in DataSetFileParsing.enumerator(testing_file):
#		if not(record[1] in results["Distribution"]):
#			results["Distribution"][record[1]] = [0.0, 0.0, 0.0]
#		results["Distribution"][record[1]][2] += 1
#		results["Total"] += 1

#		if record[1] == decision_tree.process_record(record):
#			results["Correct"] += 1
#			results["Distribution"][record[1]][0] += 1
#		else:
#			results["Incorrect"] += 1
#			results["Distribution"][record[1]][1] += 1

#	distribution = {}
#	for item in results["Distribution"]:
#		distribution[item] = results["Distribution"][item][0] / results["Distribution"][item][2]
#	results["Distribution"] = distribution
#	return results